<?php

namespace App\Common\Http\Request;

use Hyperf\Validation\Request\FormRequest;

class UserRequest extends FormRequest
{
    protected $scenes = [
        'register' => ['username', 'password', 'password_confirmation', 'phone'],
        'login' => ['username', 'password', 'loginType'],
    ];

    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }


    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'username' => 'required',
            'password' => 'required|min:6|max:18',
            'password_confirmation' => 'required|same:password',
            'phone' => ["regex:/^0{0,1}(13[0-9]|15[7-9]|153|156|18[7-9])[0-9]{8}$/"],
            'loginType' => 'integer'
        ];
    }

    public function messages(): array
    {
        return [
            'username.required' => '姓名必填',
            'password.required' => '密码必填',
            'password.min' => '密码至少6位，最多18位',
            'password.max' => '密码至少6位，最多18位',
            'password_confirmation.required' => '确认密码必填',
//            'password.confirmed' => '两次输入密码不一致',
            'password_confirmation.same' => '两次输入密码不一致',
            'phone.regex' => '手机号格式不正确',
            'loginType.integer' => '参数错误'
        ];
    }
}